#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (int argc, char const* argv[])
{
    int m, n, t, h, l, sum, ans;

    while (scanf("%d %d", &n, &m) != EOF) {
        if (n > m) { 
            t = n; n = m; m = t; 
        }

        if (m == n) {
            ans = 0;
        } else {
    
            l = (int)sqrt(n-1);
            h = (int)sqrt(m-1);

            n -= l * l;
            m -= h * h;
    
            sum = 0;
            if (n % 2 == 0) {
                n--; l--; sum--;
            }
            
            if (m >= n && m <= n+2*(h-l)) {
                if (m % 2 == 1) {
                    ans = (h-l)*2+sum;
                } else {
                    ans = (h-l)*2+sum-1;
                }
            } else {
                sum += 2*(h-l);
                if (m < n) {
                    ans = sum + n - m;
                } else {
                    ans = sum + m - n - 2 * (h-l);
                }
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}
